package Client;
import javax.swing.*;


import Entities.Admin;

import java.awt.*;
import java.awt.event.*;
import java.io.IOException;

//public class mainPage implements ActionListener{
//	JFrame Nframe;
//	Boardb mpanel;
//	Board board;
//	public mainPage(Voter v, Board board){
//		this.board = board;
//		Nframe = new JFrame("Online Voting System!");
//		Nframe.setSize(600,600);
//		Nframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//		Nframe.setResizable(true);
//		try {
//			mpanel = new Boardb(v);
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		Nframe.setContentPane(mpanel);	
//
//		JButton back = new JButton("Back");
//		back.setBounds(60, 350, 150, 30);
//		back.addActionListener(this);
//		back.setActionCommand("back");
//		mpanel.add(back);
//		back.setVisible(true);
//		Nframe.setVisible(false);
//	}
//
//	public void setV(){
//		Nframe.setVisible(true);
//	}
//
//	public void actionPerformed(ActionEvent e){
//		if(e.getActionCommand().equals("back")){
//			this.setV2();
//			board.setVisible(true);
//		}
//	}
//
//	private void setV2() {
//		Nframe.setVisible(false);
//	}
//}
@SuppressWarnings("serial")
class addPanel extends JPanel implements ActionListener{	
	JLabel titleLabel,category;
	JTextField categoryT;
	JButton ok;
	Admin ad;
	JFrame mframe;
	JButton back = new JButton("Back");
	public addPanel(Admin ad,JFrame mframe) {
		back.setBounds(150, 110, 70, 30);
		back.addActionListener(this);
		back.setActionCommand("back");
		add(back);
		this.mframe = mframe;
		this.ad = ad;
		setLayout(null); 	
		setBackground(Color.WHITE);	
		
		titleLabel = new JLabel("Add New Panel");
		category = new JLabel("Category");
		ok = new JButton("Ok");
		categoryT = new JTextField();
		
		titleLabel.setBounds(200,20,400,30);		// x/y/width/length
		category.setBounds(150,70,70,30);
		categoryT.setBounds(230,70,150,30);
		ok.setBounds(230, 110, 150, 30);
		
		titleLabel.setFont(new Font("Dialog", Font.PLAIN, 24));
		
		ok.addActionListener(this);
		ok.setActionCommand("ok");	
		add(titleLabel);
		add(ok);
		add(category);
		add(categoryT);

		titleLabel.setVisible(true);
		ok.setVisible(true);
		category.setVisible(true);
		categoryT.setVisible(true);
	}
	
	public void actionPerformed(ActionEvent e){	
		if(e.getActionCommand().equals("ok")){
			VotingClient client = new VotingClient();
			int rsIncoming = 0;
			try {
				rsIncoming = Integer.parseInt(client.sendMessage("addPanel#"+categoryT.getText()));
			} catch (IOException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			mframe.getContentPane().removeAll();
			mframe.repaint();
			JPanel p = new BoardAd(ad,mframe);
			p.setBounds(0, 0, 600, 600);
			mframe.add(p);//.setV3();
			mframe.validate();
			mframe.repaint();
		}
		else if(e.getActionCommand().equals("back")){
			mframe.getContentPane().removeAll();
			mframe.repaint();
			JPanel p = new BoardAd(ad,mframe);
			p.setBounds(0, 0, 600, 600);
			mframe.add(p);//.setV3();
			mframe.validate();
			mframe.repaint();
		}
	}
}

